package shiyl.use.springboot;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.util.ClassUtils;
import org.springframework.util.StringUtils;
import shiyl.use.springboot.config.CustomerDefinition;
import shiyl.use.springboot.config.fabric.FabricDefinitionMng;

import java.nio.file.Path;
import java.nio.file.Paths;

/**
 * @author megapro
 */
@SpringBootApplication
@EnableConfigurationProperties({
        CustomerDefinition.class,
        FabricDefinitionMng.class})
public class UseSpringbootConfigApplication {

    public static void main(String[] args) {
        String userDir = System.getProperty("user.dir");
        String prjClazzPath = ClassUtils.getDefaultClassLoader().getResource("").getPath();
        String prjPath = prjClazzPath.replace("/target/classes/", "");
        System.out.println(">>>>>>> user.dir     = " + userDir);
        System.out.println(">>>>>>> project.path = " + prjPath);
        System.out.println(">>>>>>> class.path   = " + prjClazzPath);

        if (!userDir.equals(prjPath)) {
            System.err.println("user.dir 和 工程路径project.path 不一致，本例子有可能加载不到${prj_path}/config/目录下的配置文件!!!!");
            System.out.println("原因: 本工程位于Module工程集中，user.dir不是工程路径，加载不到config目录。");
            System.out.println("提示: 1.请到工程目录下运行 mvn spring-boot:run 启动;2.或者用IDE单独打开本工程，而不是作为模块集打开！");
            return;
        }

        SpringApplication.run(UseSpringbootConfigApplication.class, args);
    }

}

